// 数据库表类型定义

export interface Profile {
  id: string;
  user_id: string;
  phone: string;
  nickname?: string;
  avatar_url?: string;
  role: 'user' | 'admin';
  created_at: string;
  updated_at: string;
}

export interface Category {
  id: string;
  name: string;
  description?: string;
  image_url?: string;
  sort_order: number;
  created_at: string;
}

export interface Product {
  id: string;
  name: string;
  description?: string;
  price: number;
  original_price?: number;
  category_id?: string;
  images?: string[];
  sizes?: string[];
  colors?: string[];
  stock: number;
  is_featured: boolean;
  is_active: boolean;
  created_at: string;
  updated_at: string;
  category?: Category;
}

export interface CartItem {
  id: string;
  user_id: string;
  product_id: string;
  quantity: number;
  size?: string;
  color?: string;
  created_at: string;
  updated_at: string;
  product?: Product;
}

export interface Order {
  id: string;
  user_id: string;
  order_number: string;
  total_amount: number;
  status: 'pending' | 'paid' | 'shipped' | 'delivered' | 'cancelled';
  shipping_address?: ShippingAddress;
  payment_method?: string;
  notes?: string;
  created_at: string;
  updated_at: string;
  order_items?: OrderItem[];
}

export interface OrderItem {
  id: string;
  order_id: string;
  product_id?: string;
  product_name: string;
  product_image?: string;
  price: number;
  quantity: number;
  size?: string;
  color?: string;
  created_at: string;
}

export interface ShippingAddress {
  name: string;
  phone: string;
  province: string;
  city: string;
  district: string;
  address: string;
  postal_code?: string;
}

// 扩展类型定义

export interface ProductWithCategory extends Product {
  category: Category;
}

export interface CartItemWithProduct extends CartItem {
  product: Product;
}

export interface OrderWithItems extends Order {
  order_items: OrderItem[];
}

// 表单类型定义

export interface ProductFormData {
  name: string;
  description: string;
  price: number;
  original_price?: number;
  category_id: string;
  images: string[];
  sizes: string[];
  colors: string[];
  stock: number;
  is_featured: boolean;
  is_active: boolean;
}

export interface CategoryFormData {
  name: string;
  description: string;
  image_url?: string;
  sort_order: number;
}

export interface CheckoutFormData {
  shipping_address: ShippingAddress;
  payment_method: string;
  notes?: string;
}

export interface ProfileFormData {
  nickname: string;
  avatar_url?: string;
}

// API 响应类型

export interface ApiResponse<T> {
  data: T;
  error?: string;
}

export interface PaginatedResponse<T> {
  data: T[];
  count: number;
  page: number;
  limit: number;
  total_pages: number;
}

// 购物车相关类型

export interface AddToCartData {
  product_id: string;
  quantity: number;
  size?: string;
  color?: string;
}

export interface UpdateCartItemData {
  quantity: number;
  size?: string;
  color?: string;
}

// 筛选和搜索类型

export interface ProductFilters {
  category_id?: string;
  min_price?: number;
  max_price?: number;
  sizes?: string[];
  colors?: string[];
  is_featured?: boolean;
  search?: string;
}

export interface SortOption {
  value: string;
  label: string;
}

// 统计类型

export interface DashboardStats {
  total_products: number;
  total_orders: number;
  total_users: number;
  total_revenue: number;
  recent_orders: Order[];
}